# MultiRAG

This example runs a modified RAG pipeline which creates and aggregates synthetic queries and their search results to answer more difficult user questions such as `"Compare the two books"`. For a more comprehensive example, please visit [Basic Example](/examples/basic-example).

```bash
# Launch the application
# If using a venv, replace `uvicorn` with `venv_path/bin/uvicorn`
uvicorn r2r.examples.academy.app:app
```

This creates a more advanced pipeline which overrides the basic RAG pipeline logic.

```python
class SyntheticRAGPipeline(BasicRAGPipeline):
    def __init__(
        self,
        llm: LLMProvider,
        generation_config: GenerationConfig,
        db: VectorDBProvider,
        embedding_model: str,
        embeddings_provider: OpenAIEmbeddingProvider,
        logging_provider: Optional[LoggingDatabaseConnection] = None,
        system_prompt: Optional[str] = DEFAULT_SYSTEM_PROMPT,
        task_prompt: Optional[str] = DEFAULT_TASK_PROMPT,
    ) -> None:
        logger.debug(f"Initalizing `SyntheticRAGPipeline`")

        super().__init__(
            llm,
            generation_config,
            db,
            embedding_model,
            embeddings_provider,
            logging_provider=logging_provider,
            system_prompt=system_prompt,
            task_prompt=task_prompt,
        )

    def transform_query(self, query: str) -> list[str]:
        """
        Transforms the query into a list of strings.
        """
        print(f"Transforming query: {query}")
        prompt = (
            "Use the query that follows to write a comma separated three queries "
            "that will be used to retrieve the relevant materials. DO NOT generate "
            "queries which require multiple document types. E.g. ask for `lecture notes "
            "with information about X` or `readings that cover topic Y`.\n\n## Query:\n"
            "{query}\n\n## Response:".format(query=query)
        )
        completion = self.generate_completion(prompt)
        transformed_queries = (
            completion.choices[0].message.content.strip().split("\n")
        )
        print(f"Transformed Queries: {transformed_queries}")
        return transformed_queries
```

An example client script can then be ran as shown below to run demonstrate MultiRAG.
```bash
python -m r2r.examples.academy.run_client
```